﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Configuration;
using System.Net;

namespace MGI.Logica
{
    public class MGIMail
    {

        static public bool SendMail(string to, string subject, string body)
        {
            try
            {
                String serverMail = ConfigurationManager.AppSettings.Get("serverMail");
                String userMail = ConfigurationManager.AppSettings.Get("userMail");
                String passMail = ConfigurationManager.AppSettings.Get("passMail");
                String fromMail = ConfigurationManager.AppSettings.Get("fromMail");

                MailMessage msg = new MailMessage();
                msg.To.Add(new MailAddress(to));
                msg.From = new MailAddress(fromMail);
                msg.Subject = subject;
                msg.Body = body;

                SmtpClient clienteSmtp = new SmtpClient(serverMail);
                clienteSmtp.Credentials = new NetworkCredential(userMail, passMail);

                clienteSmtp.Send(msg);

            }

            catch (Exception)
            {

                throw new Exception("No se pudo enviar el correo");

            }
            return true;

        }




    }

}


